package offer;

/**
 * @Author Elephas
 * @Date 2022/1/13
 **/
public class ReverseList {

    /*
        头插法
     */
    public ListNode reverseList(ListNode head){
        if(head == null){
            return null;
        }
        ListNode fakeHead = new ListNode(0);
        fakeHead.next = null;
        ListNode cur = head,temp;
        while(cur != null){
            temp = cur;
            cur = cur.next;
            temp.next = fakeHead.next;
            fakeHead.next = temp;
        }
        return fakeHead.next;
    }
}
